﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YmtAuth.Common.Utility;

namespace YmtUserAuth.DataImport
{
    public class UserCredential
    {
        public object Value { get; set; }
        public string _id { get; set; }

        /// <summary>
        /// 创建用户凭据
        /// </summary>
        /// <param name="loginId"></param>
        /// <param name="password"></param>
        /// <param name="email"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public static IEnumerable<UserCredential> CreateCredential(string loginId, string password, string email, int userId)
        {
            // Console.WriteLine("{0},{1},{2}", CryptoUtil.Md5Encrypt(string.Format("{0}&{1}", loginId, password)), loginId, password);
            //按不同认证策略生成用户凭据
            yield return new UserCredential
            {
                _id = CryptoUtil.Md5Encrypt(string.Format("{0}&{1}", loginId.ToLower(), password)),
                Value = userId
            };
            yield return new UserCredential
            {
                _id = CryptoUtil.Md5Encrypt(string.Format("{0}&{1}", email == "NULL" ? "" : email.ToLower(), password)),
                Value = userId
            };
        }

        public override string ToString()
        {
            return string.Format("[_id={0},Value={1}]", this._id, this.Value);
        }
    }
}
